import cache from '@/libs/cache'
import { LOGIN_USER_INFO, ACCESS_TOKEN } from './mutation-types'

const getters = {
  isMobile: state => state.app.isMobile,
  lang: state => state.app.lang,
  theme: state => state.app.theme,
  color: state => state.app.color,
  multiTab: state => state.app.multiTab,
  token: state => {
    let token = state.user.token
    if (!token) token = cache.get(ACCESS_TOKEN)
    return token
  },
  userInfo: (state) => {
    let info = state.user.info;
    if (!(info && info.token)) {
      info = cache.get(LOGIN_USER_INFO) || {};
    }
    info.name = info.name || 'Serati Ma'
    info.avatar = info.avatar || 'https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png'
    return info
  },
  asyncRoutes: state => state.permission.asyncRoutes,
}

export default getters
